var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var gulp = require('gulp');

gulp.task('default', function () {
    gulp.src('./*.js')       // 路径问题：gulpfile.js为路径的起点。此路径表示js文件下的所有js文件。
    .pipe(concat('popup.js'))   //合并成的js文件名称
    //.pipe(uglify())            //压缩
    .pipe(gulp.dest('app'));
});
class numImage extends HTMLElement
{
    constructor()
    {
        super();
        this.fontsize = 15;
        this.width = this.height = 25;
        this.content = document.createElement('canvas');
        this.content.width = this.width;
        this.content.height = this.height;
    }
    connectedCallback()
    {
        this.ctx = this.content.getContext('2d');
        this.ctx.lineWidth = 2;
        this.ctx.strokeStyle = this.getAttribute("color");
        this.ctx.beginPath();
        this.ctx.arc(this.width/2,this.height/2,(this.width-this.ctx.lineWidth)/2,0,2*Math.PI);
        this.ctx.closePath();
        this.ctx.stroke();
        this.ctx.font = this.fontsize + "px serif";
        this.ctx.fillText(this.getAttribute("data"),this.width/2-this.fontsize/2,this.height/2+this.fontsize/2.8);
        this.appendChild(this.content);
    }
}
window.customElements.define('num-image',numImage)
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This extension loads the saved background color for the current tab if one
// exists. The user can select a new background color from the dropdown for the
// current page, and it will be saved as part of the extension's isolated
// storage. The chrome.storage API is used for this purpose. This is different
// from the window.localStorage API, which is synchronous and stores data bound
// to a document's origin. Also, using chrome.storage.sync instead of
// chrome.storage.local allows the extension data to be synced across multiple
// user devices.
const cheerio = require('cheerio');
const http = require('http');
const iconv = require('iconv-lite');

document.addEventListener('DOMContentLoaded', () => {
    const options = {
        url: 'http://www.baidu.com/',
        header: {
          'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.'
        }
     }
     http.get(options, function(res) {
      const chunks = [];
      res.on('data', function(chunk) {
        chunks.push(chunk);
      });
      res.on('end', function() {
        const html = iconv.decode(Buffer.concat(chunks), 'utf8');
        console.log(html);
        const $ = cheerio.load(html);
      });
    });
})
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');

module.exports = {
  entry: {
    main:'./popup.js',
    num:'numImage.js',
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename:'popup.js'
  },
  optimization:{
    minimize:true,
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: 'popup.html',
      filename:'popup.html'
    })
  ]
};